import { getUserInfo, logout, checkIsPcLogin } from 'config/api';
import { Toast } from 'antd-mobile';
import router from 'umi/router';
export default {
  state: {
    isLogin: false,
    userinfo: {
      headimgurl: '未登录',
      name: '未登录',
      nickname: '未登录',
      id_card: '未登录',
      telephone: '未登录'
    },
    headerData: [
      {
        text: '本月分红',
        data: '0 元'
      },
      {
        text: '牛币',
        data: 0
      },
      {
        text: '待返牛款',
        data: '0 元'
      }
    ],
    secondDivData: [
      {
        text: '牛圈0只牛',
        iconSrc: require('src/assets/pasture.svg'),
        url: '/layout/myLarn?tabName=muniuren'
      },
      {
        text: '果园0课树',
        iconSrc: require('src/assets/购买记录.png'),
        url: '/layout/inviteQCode?tabName=muniuren'
      },
      {
        text: '购买记录',
        iconSrc: require('src/assets/购买记录.png'),
        url: '/layout/record?tabName=muniuren&title=购买记录'
      }
    ],
    listData: [
      [
        {
          iconSrc: require('src/assets/账号设置.png'),
          text: '账号设置',
          url: '/layout/setting?tabName=muniuren'
        }
        // {
        //   iconSrc:  require('src/assets/我的银行卡.png'),
        //   text: '我的银行卡',
        //   url: '/layout/bankCardList?tabName=muniuren'
        // }
      ],
      [
        {
          iconSrc: require('src/assets/保单.png'),
          text: '保单与合同',
          url: '/layout/myLarn?tabName=muniuren'
        },
        // {
        //   text: '我的牛圈',
        //   iconSrc: require('src/assets/pasture.svg'),
        //   url: '/layout/myLarn?tabName=muniuren'
        // },
        {
          iconSrc: require('src/assets/我的活动.png'),
          text: '我的活动',
          url: '/layout/activity?tabName=muniuren'
        },
        // {
        //   iconSrc: require('src/assets/message.svg'),
        //   text: '我的消息',
        //   url: '/layout/record?tabName=muniuren&title=我的消息'
        // }
        // {
        //   iconSrc:  require('src/assets/我的客服.png'),
        //   text: '我的专属客服',
        //   url: '/layout/myKefu?tabName=muniuren'
        // },
        // {
        //   iconSrc:  require('src/assets/我的二维码.png'),
        //   text: '我的邀请二维码',
        //   url: '/layout/inviteQCode?tabName=muniuren'
        // }
      ]
      // [
      //   {
      //     iconSrc:  require('src/assets/推广佣金.png'),
      //     text: '推广佣金',
      //     url: '/layout/yongjin?tabName=muniuren'
      //   },
      //   {
      //     iconSrc:  require('src/assets/优惠券.png'),
      //     text: '优惠券',
      //     url: '/layout/inviteQCode?tabName=muniuren'
      //   },
      //   {
      //     iconSrc:  require('src/assets/兑换.png'),
      //     text: '橙点兑换牛币',
      //     url: '/layout/inviteQCode?tabName=muniuren'
      //   }
      // ]
    ]
  },
  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    }
  },
  effects: {
    *getUserInfoEff(action, { call, put, select }) {
      let { isLogin } = yield call(checkIsPcLogin);
			console.log("​*getUserInfoEff -> isLogin", isLogin)
      yield put({
        type:'save',
        payload: {isLogin}
      })
      if (isLogin) {
        let res = yield call(getUserInfo);
        console.log('​*getUserInfoEff -> res', res);
        yield put({
          type: 'save',
          payload: { userinfo: res }
        });
      }
    },
    *logoutEff(action, { call, put }) {
      let { code, msg } = yield call(logout);
      if (code === 0) {
        Toast.info(msg);
        router.push('/?tabName=main');
      }
    }
  }
};
